package com.example.demo.controller.resp;

import lombok.Data;

@Data
public class Response<T> {

    private static int SUCCESS = 0;
    private static int FALSE = -1;

    private int code;
    private boolean success;
    private T data;
    private String errMsg;

    public Response() {

    }

    public static <T> Response<T> success(T data) {
        Response<T> res = new Response<T>();
        res.setCode(SUCCESS);
        res.setSuccess(true);
        res.setData(data);
        return res;
    }

    public static <T> Response<T> fail(String msg) {
        Response<T> res = new Response<T>();
        res.setCode(FALSE);
        res.setSuccess(false);
        res.setData(null);
        res.setErrMsg(msg);
        return res;
    }

}
